'use strict'
const path = require('path')

function resolve(dir) {
  return path.join(__dirname, dir)
}

const defaultSettings = require('./src/settings.js')
const title = defaultSettings.title || 'Admin'

const port = process.env.port || process.env.npm_config_port || 80 // dev port

module.exports = {
  publicPath: '/',
  outputDir: 'dist',
  assetsDir: 'static',
  lintOnSave: false,
  productionSourceMap: true,
  devServer: {
    port: port,
    open: true,
    disableHostCheck: true,
    proxy: {
      '/crm': {
        //target: 'http://crms.fxsk100.com',
        target:'http://crm.sykj888.cn',
        changeOrigin: true
      }
    },
    overlay: {
      warnings: false,
      errors: true
    }
  },
  configureWebpack: config => {
    config.name = title
    if (process.env.NODE_ENV === 'production') {
      config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
    }
    // config.externals = {
    //   axios: 'axios',
    //   vue: 'Vue',
    //   'vue-router': 'VueRouter',
    //   lodash: '_',
    //   'element-ui': 'ELEMENT'
    // }
  },
  chainWebpack(config) {
    config.module
      .rule('svg')
      .exclude.add(resolve('src/icons'))
      .end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()
  }
}
